package com.likersai.funa.pojo.vo.model;

import com.likersai.funa.constant.MsgAndCode;
import lombok.Data;

import static com.likersai.funa.constant.ResponseMsg.SUCCESS;

/**
 * 查询返回结果
 *
 * @author sun.ye
 * @since 2021-07-19 20:36
 */
@Data
public class Result<T> {

    private String code;
    private String message;
    private T data;


    private Result(MsgAndCode msgAndCode) {
        this.setCode(msgAndCode.getCode());
        this.setMessage(msgAndCode.getMessage());
    }

    public static<T> Result<T> getSuccess(T data){
        Result<T> result = new Result<>(SUCCESS);
        result.setData(data);
        return result;
    }

    public static<T> Result<T> getFail(MsgAndCode msgAndCode){
        return new Result<>(msgAndCode);
    }

}